package gxt.visual.selection.event;

import java.util.List;

import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.util.Util;

/**
 * @author eugenp
 */
public class GenericSelectionEvent< T > extends BaseEvent{
	protected List< T > selection;
	
	/**
	 * Creates a new selection event.
	 * @param providerToSet the selection provider
	 * @param selectionToSet the selection
	 */
	public GenericSelectionEvent(  final List< T > selectionToSet ){
		super( Events.Select );
		
		this.selection = selectionToSet;
	}
	/**
	 * Creates a new selection event.
	 * @param providerToSet the selection provider
	 * @param selectionToSet the selection
	 */
	@SuppressWarnings( "unchecked" )
	public GenericSelectionEvent( final T selectionToSet ){
		super( Events.Select );
		
		this.selection = Util.createList( selectionToSet );
	}
	
	//
	/**
	 * Returns the first selected item.
	 * @return the selected item
	 */
	public T getSelectedItem(){
		if( this.selection.size() > 0 ){
			return this.selection.get( 0 );
		}
		return null;
	}
	
	/**
	 * Returns the selection.
	 * @return the selection
	 */
	public List< T > getSelection(){
		return this.selection;
	}
	
}
